When compiling a program, a programmer needs to define a code segment start address and a data segment start address. An address of each instruction and an address of each piece of data can be obtained only after these addresses are obtained. A jump instruction and a function call instruction can be executed only after addresses of the instructions are obtained, and a memory access instruction can be executed only after an address of data is obtained.
However, when different programmers compile respective programs, and when one programmer compiles different programs, how to define a code segment start address and a data segment start address of each program becomes a key issue. To address this issue, concepts and technologies of a virtual address and a physical address are introduced.
With a virtual address technology, only a virtual address is displayed to a programmer during programming. In this case, both a code segment start address and a data segment start address of any program are fixed values. In other words, a code segment start address of a program is the same as a code segment start address of another program; and similarly, a data segment start address of a program is also the same as a data segment start address of another program. Therefore, the programmer does not need to define or determine the values of the code segment start address and the data segment start address.
However, when a program starts to be executed, an operating system (OS) searches for a currently available physical address, and maps a virtual address used by the program to the physical address. Therefore, when a plurality of programs are executed at the same time, they are actually at different physical addresses. This ensures normal execution of the programs.
A physical address space in a memory is arranged in unit of a page. When managing the memory, the operating system divides the physical address space into consecutive pages. A virtual address space is also arranged in unit of a page and divided into consecutive pages. The virtual address includes two parts: a virtual page number (VPN) and an intra-page offset. Correspondingly, the physical address also includes two parts: a physical frame number (PFN) (also called a physical page number) and an intra-page offset. Therefore, mapping a virtual address to a physical address is a process of mapping a page number of the virtual address to a page number of the physical address. A mapping relationship from the virtual page number to the physical page number is stored in the memory by using a page table entry. To speed up a process of translating the virtual page number to the physical page number, a part of space, that is, a translation lookaside buffer (TLB), in a cache of a processing chip is allocated to store some page table entries.
Due to limited cache space, a quantity of page table entries stored in the cache is limited. As a result, in a process of translating a virtual address to a physical address by using the page table, a lot of TLB misses occur, that is, a corresponding physical page number for a virtual page number cannot be found in the page table in the cache. This causes a high delay in program processing, and therefore reduces processing efficiency of the processing chip.